package com.tedu.jdbc;

import com.tedu.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 *
 * @author zq
 * @version 1.0
 * @create 2024-07-30 14:39
 * @since jdk1.8
 */
public class JDBCDemo03 {
    public static void main(String[] args)
    {
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要删除的编号：");
        int id = sc.nextInt();
        try {
            conn = JDBCUtils.getConnection();
            conn.createStatement();
            String sql = "delete from userinfo where id = '"+id+"'";
            ps = conn.prepareStatement(sql);
            int i = ps.executeUpdate();
            if (i > 0) {
                System.out.println("删除成功");
            } else {
                System.out.println("删除失败");
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }finally {
            JDBCUtils.close(rs,ps,conn);
        }
    }
}
